x = document.body.appendChild(document.createElement('div'));
x.style.height = '10px';
x.style.width = '10px';
x.style.backgroundColor = 'black';
x.style.position = 'absolute';
x.style.top = '5px';
x.style.left = '5px';

function pickPointAndMove(element) {
    var pointX = Math.round(Math.random() * window.innerWidth),
        pointY = Math.round(Math.random() * window.innerHeight),
        top = parseInt(element.style.top),
        left = parseInt(element.style.left),
        speedX = (pointX / left),
        speedY = (pointY / top);

        y = x.cloneNode();
        y.style.backgroundColor = 'red';
        y.style.height = '5px';
        y.style.width = '5px';
        y.style.top = pointY + 'px';
        y.style.left = pointX + 'px';

        document.body.appendChild(y);

    function move() {
        var distance = Math.sqrt(Math.pow(left - pointX, 2), 
                                 Math.pow(top - pointY, 2));

        if (distance < 1000) {
            y.parentElement.removeChild(y);
            return pickPointAndMove(element);
        }

        top += speedY;
        left += speedX;

        element.style.top = top + 'px';
        element.style.left = left + 'px';

        setTimeout(move, 5);
    };

    move();
};

pickPointAndMove(x);